package seng550.webservice.client;

import java.util.Calendar;
import java.util.Date;

public class WholeSaleService {
	private String _endPoint=null;
	public WholeSaleService(){
	}
	public WholeSaleService(String urlEndPoint){
		this._endPoint=urlEndPoint;
	}
	private seng550.webservice.client.WholeSaleServiceStub createConnection() throws Exception{
		seng550.webservice.client.WholeSaleServiceStub ws;
		if (this._endPoint==null){
			ws=new seng550.webservice.client.WholeSaleServiceStub();
		}else{
			ws=new seng550.webservice.client.WholeSaleServiceStub(this._endPoint);
		}
		return ws;
	}
	
	public WholeSaleServiceStub.Item getItemDetail(String code) throws Exception{
		WholeSaleServiceStub.Item ret=null;
		seng550.webservice.client.WholeSaleServiceStub ws;
		WholeSaleServiceStub.GetItemDetail p1;
		WholeSaleServiceStub.GetItemDetailResponse r1;
		
		ws=this.createConnection();
		p1=new WholeSaleServiceStub.GetItemDetail();
		p1.setParam0(code);
		
		r1=ws.getItemDetail(p1);
		ret=r1.get_return();
		
		return ret;
	}
	
    public boolean checkInventory(String itemID, int quantity, Date date ) throws Exception{
		boolean ret;
		
		seng550.webservice.client.WholeSaleServiceStub ws;
		WholeSaleServiceStub.CheckInventory p1;
		WholeSaleServiceStub.CheckInventoryResponse r1;
		
		ws=this.createConnection();
		p1=new WholeSaleServiceStub.CheckInventory();
		p1.setParam0(itemID);
		p1.setParam1(quantity);
		Calendar cal=Calendar.getInstance();
		cal.setTime(date);		
		p1.setParam2(cal);
		
		r1=ws.checkInventory(p1);
		
		ret=r1.get_return();
		
		return ret;
    }   
    
    public int putPurchaseOrder(String[] itemIDs, int[] quantities) throws Exception {
		int ret;
		seng550.webservice.client.WholeSaleServiceStub ws;
		WholeSaleServiceStub.PutPurchaseOrder p1;
		WholeSaleServiceStub.PutPurchaseOrderResponse r1;
		
		ws=this.createConnection();
		p1=new WholeSaleServiceStub.PutPurchaseOrder();
		p1.setParam0(itemIDs);
		p1.setParam1(quantities);
		
		r1=ws.putPurchaseOrder(p1);
		
		ret=r1.get_return();
		
		return ret;
    }
        
    public WholeSaleServiceStub.PurchaseOrder getPurchaseOrderInformation(int orderConfirmationNumber) throws Exception{
    	WholeSaleServiceStub.PurchaseOrder ret;
		seng550.webservice.client.WholeSaleServiceStub ws;
		WholeSaleServiceStub.GetPurchaseOrderInformation p1;
		WholeSaleServiceStub.GetPurchaseOrderInformationResponse r1;
		
		ws=this.createConnection();
		p1=new WholeSaleServiceStub.GetPurchaseOrderInformation();
		p1.setParam0(orderConfirmationNumber);
		
		r1=ws.getPurchaseOrderInformation(p1);
		
		ret=r1.get_return();
		
		return ret;
    }
}
